<html lang="en" xmlns:th="http://www.thymeleaf.org">
<div class="panel" style="padding-bottom: 200px">
    <form id="form_specialButtonAuth_input" class="form-horizontal" autocomplete="off">

        <div class="panel-heading header"><h3 class="panel-title">业务按钮</h3></div>

        <input type="hidden" id="keyId" name="keyId" th:value="${specialButtonAuth?.id}" />
        <input type="hidden" id="processBriefId" name="processBriefId" th:value="${processBriefId}" />

        <div class="form-group">
            <label class="col-md-3 control-label">按钮名称<i class="fa fa-asterisk txt-color-red"></i></label>
            <div class="col-md-7">
                <input type="text" name="name" id="name" th:value="${specialButtonAuth?.name}" class="form-control" placeholder="按钮名称">
            </div>
        </div>

        <div class="form-group">
            <label class="col-md-3 control-label">关键字<i class="fa fa-asterisk txt-color-red"></i></label>
            <div class="col-md-7">
                <input type="text" name="buttonKey" id="buttonKey" th:value="${specialButtonAuth?.buttonKey}" class="form-control" placeholder="关键字">
            </div>
        </div>

        <div class="panel-heading header"><h3 class="panel-title">参与者信息</h3></div>

        <div class="form-group">
            <label class="col-md-3 control-label">是否所有人参与<i class="fa fa-asterisk txt-color-red"></i></label>
            <div class="col-md-7">
                <div class="radio">
                    <input type="radio" name="ifAll" id="ifAll0" value="0"  class="magic-radio" th:checked="${specialButtonAuth?.ifAll == 0}" />
                    <label for="ifAll0">否</label>
                    <input type="radio" name="ifAll" id="ifAll1" value="1" class="magic-radio" th:checked="${specialButtonAuth==null || specialButtonAuth?.ifAll == 1}"  />
                    <label for="ifAll1">是</label>
                </div>
            </div>
        </div>

        <div id="participantDiv" th:hidden="${specialButtonAuth==null || specialButtonAuth?.ifAll == 1}">
            <div class="form-group">
                <label class="col-md-3 control-label">
                    <a href="javascript:void(0);" class="btn-link text-semibold" onclick="department_select()">部门</a>
                </label>
                <div class="col-md-7">
                    <input readonly type="text" id="departmentNames" class="form-control" th:value="${participant?.departmentNames}" />
                    <input type="hidden" id="departmentIds" name="departmentIds" th:value="${participant?.departmentIds}" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-3 control-label">
                    <a href="javascript:void(0);" class="btn-link text-semibold" onclick="post_select()">岗位</a>
                </label>
                <div class="col-md-7">
                    <input readonly type="text" id="postNames" class="form-control" th:value="${participant?.postNames}"/>
                    <input type="hidden" id="postIds" name="postIds" th:value="${participant?.postIds}" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-3 control-label">
                    <a href="javascript:void(0);" class="btn-link text-semibold" onclick="power_select()">职权</a>
                </label>
                <div class="col-md-7">
                    <input readonly type="text" id="powerNames" class="form-control" th:value="${participant?.powerNames}" />
                    <input type="hidden" id="powerIds" name="powerIds" th:value="${participant?.powerIds}" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-3 control-label">
                    <a href="javascript:void(0);" class="btn-link text-semibold" onclick="group_select()">群组</a>
                </label>
                <div class="col-md-7">
                    <input readonly type="text" id="groupNames" class="form-control" th:value="${participant?.groupNames}" />
                    <input type="hidden" id="groupIds" name="groupIds" th:value="${participant?.groupIds}" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-3 control-label">
                    <a href="javascript:void(0);" class="btn-link text-semibold" onclick="user_select()">用户</a>
                </label>
                <div class="col-md-7">
                    <input readonly type="text" id="userNames" class="form-control" th:value="${participant?.userNames}" />
                    <input type="hidden" id="userIds" name="userIds" th:value="${participant?.userIds}" />
                </div>
            </div>

        </div>

    </form>
</div>

<script th:inline="javascript">

    var data = {

    };

    $(function(){
        fn_specialButtonAuth_input_validate();
    });

    //参与者信息显示隐藏
    $(":radio[name='ifAll']").on("click", function(){
        if($(this).val() == 1){
            $("#participantDiv").hide();
        }else{
            $("#participantDiv").show();
        }
    });

    // ===========================参与者信息=================================

    function department_select(){
        var deptIds = $("#form_specialButtonAuth_input #departmentIds").val();
        __departments_dialog_select("specialButtonAuth_input_department_select", deptIds, function(data){
            __layX_close("specialButtonAuth_input_department_select");
            $("#form_specialButtonAuth_input #departmentNames").val(data.name);
            $("#form_specialButtonAuth_input #departmentIds").val(data.id);
        })
    }

    function post_select(){
        var postIds = $("#form_specialButtonAuth_input #postIds").val();
        var postNames = $("#form_specialButtonAuth_input #postNames").val();
        __posts_dialog_select("specialButtonAuth_input_post_select", postIds, postNames, function(data){
            $("#form_specialButtonAuth_input #postNames").val(data.names);
            $("#form_specialButtonAuth_input #postIds").val(data.ids);
            __layX_close("specialButtonAuth_input_post_select");
        });
    }

    function power_select(){
        var powerIds = $("#form_specialButtonAuth_input #powerIds").val();
        var powerNames = $("#form_specialButtonAuth_input #powerNames").val();
        __powers_dialog_select("specialButtonAuth_input_power_select", powerIds, powerNames, function(data){
            $("#form_specialButtonAuth_input #powerNames").val(data.names);
            $("#form_specialButtonAuth_input #powerIds").val(data.ids);
            __layX_close("specialButtonAuth_input_power_select");
        });
    }

    function group_select(){
        var groupIds = $("#form_specialButtonAuth_input #groupIds").val();
        var groupNames = $("#form_specialButtonAuth_input #groupNames").val();
        __groups_dialog_select("specialButtonAuth_input_group_select", groupIds, groupNames, function(data){
            $("#form_specialButtonAuth_input #groupNames").val(data.names);
            $("#form_specialButtonAuth_input #groupIds").val(data.ids);
            __layX_close("specialButtonAuth_input_group_select");
        });
    }

    function user_select(){
        var userIds = $("#form_specialButtonAuth_input #userIds").val();
        var userNames = $("#form_specialButtonAuth_input #userNames").val();
        __users_dialog_select("specialButtonAuth_input_user_select", userIds, userNames, function(data){
            $("#form_specialButtonAuth_input #userNames").val(data.names);
            $("#form_specialButtonAuth_input #userIds").val(data.ids);
            __layX_close("specialButtonAuth_input_user_select");
        });
    }

    // ======================================================================

    function fn_specialButtonAuth_input_validate(){
        __init_validate("form_specialButtonAuth_input", {
            rules : {
                name : {
                    required : true
                },
                buttonKey : {
                    required : true
                },
                ifAll : {
                    required : true
                }
            }
        })
    }

    function fn_specialButtonAuth_save(callback) {
        if(!$("#form_specialButtonAuth_input").valid()){
            return false;
        }

        __confirm_dialog("", "确认提交吗？", function(){
            __form_save("form_specialButtonAuth_input", "/flow/specialButtonAuth/save", function(data){
                callback(data);
            })
        }, function(){
            callback();
        })

    }

</script>

</html>